package com.dh.project.utils;

import com.dh.project.model.*;

/**
 * Created by admin on 2017/4/10.
 */
public class PageUtil {


    public static Integer getPageCount(Integer count,int page_count){

        int pageCount = 0;

        if (count == 0){
            pageCount = 1;
        }

        if (count % page_count == 0){
            pageCount =count / page_count;
        }else {
            pageCount = (count / page_count) + 1;
        }
        return pageCount;
    }

    /**
     * 获取每页显示数据数量的对象
     * @param pageModel
     * @param page
     * @param page_count
     * @return
     */
    public static PageInfo getPageInfo(PageModel pageModel,int page,int page_count){
        PageInfo pageInfo = new PageInfo();
        pageInfo.setCount_info(pageModel.getPage_index());

        if (page <= 1){
            pageInfo.setStart_info(1);
        }else {
            pageInfo.setStart_info((page-1)*10);
        }

        if ((page * page_count) <= pageModel.getPage_index()){
            pageInfo.setEnd_info(page * page_count);
        }else {
            pageInfo.setEnd_info(pageModel.getPage_index());
        }
        return pageInfo;
    }

    /**
     * 获取分页链接(2条件)
     * @param obj
     * @param type
     * @return
     */
    public static String getPageHref(Object obj, int type){
        Integer id = null;
        String name = null,start_href = null,id_href = null,name_href = null;
        if (type == 1){
            Admin admin = (Admin) obj;
            id = admin.getAdmin_id();
            name = admin.getAdmin_name();
            start_href = "selectAdminList?";
            id_href = "admin_id=";
            name_href = "admin_name=";
        }else if (type == 2){
            CustomerInfo customerInfo = (CustomerInfo) obj;
            id =customerInfo.getCustomer_id();
            name = customerInfo.getCustomer_name();
            start_href = "selectCustomerList?";
            id_href = "customer_id=";
            name_href = "customer_name=";
        }else if (type == 3){
            EmployeeInfo employeeInfo = (EmployeeInfo) obj;
            id = employeeInfo.getEmployee_id();
            name = employeeInfo.getEmployee_name();
            start_href = "selectEmployeeList?";
            id_href = "employee_id=";
            name_href = "employee_name=";
        }else if (type == 4){
            EngineerPhone engineerPhone = (EngineerPhone) obj;
            id = engineerPhone.getEngineer_id();
            name = engineerPhone.getEngineer_name();
            start_href = "selectEngineerPhoneList?";
            id_href = "engineer_id=";
            name_href = "engineer_name=";
        }

        String page_href = "";
        if (id != null && name != null){
            page_href = start_href+id_href+id+"&"+name_href+name+"&page=";
        }else if (id != null){
            page_href = start_href+id_href+id+"&page=";
        }else if (name != null){
            page_href = start_href+name_href+name+"&page=";
        }else {
            page_href = start_href+"page=";
        }
        return  page_href;
    }


    /**
     *  产品类 5条件获取分页链接
     * @param obj
     * @param type
     * @return
     */
    public static String getPageHrefByFive(Object obj, int type){
        Integer condition_one = null,condition_two = null, condition_three = null ,condition_four = null, condition_five = null;
        String one_href = null,two_href = null,three_href = null,four_href=null,five_href = null, start_href = null;

        if (type == 1){//产品

            ServiceProject serviceProject = (ServiceProject) obj;
            //分类  空调 地暖 新风  7.维修类
            condition_one = serviceProject.getService_class();
            //品牌
            condition_two = serviceProject.getService_brand();
            //种类
            condition_three = serviceProject.getService_kind();
            //规格
            condition_four = serviceProject.getService_standard();
            //部件
            condition_five = serviceProject.getService_assembly();
            start_href = "selectServiceProjectList?";
            one_href = "service_class=";
            two_href = "service_brand=";
            three_href = "service_kind=";
            four_href = "service_standard=";
            five_href = "service_assembly=";

        }else if (type == 2){//维修

            ServiceProject serviceProject = (ServiceProject) obj;
            //分类  空调 地暖 新风  7.维修类
            condition_one = serviceProject.getService_class();
            start_href = "selectServiceProjectList?";
            one_href = "service_class=";
        }
        String page_href = "";
        String one_page_href = "";
        if (condition_one != null){
            one_page_href = one_href+condition_one;
        }
        if (condition_two != null){
            if (one_page_href.equals("")){
                one_page_href = two_href+condition_two;
            }else {
                one_page_href = "&"+two_href+condition_two;
            }
        }
        if (condition_three != null){
            if (one_page_href.equals("")){
                one_page_href = three_href+condition_three;
            }else {
                one_page_href = "&"+three_href+condition_three;
            }
        }
        if (condition_four != null){
            if (one_page_href.equals("")){
                one_page_href = four_href+condition_four;
            }else {
                one_page_href = "&"+four_href+condition_four;
            }
        }
        if (condition_five != null){
            if (one_page_href.equals("")){
                one_page_href = five_href+condition_five;
            }else {
                one_page_href = "&"+five_href+condition_five;
            }
        }

        if (one_page_href.equals("")){
            page_href = start_href+"&page=";
        }else {
            page_href = start_href+one_page_href+"&page=";
        }
        return  page_href;
    }
}
